# coding=utf-8
"""
Django settings for www project.

For more information on this file, see
https://docs.djangoproject.com/en/1.7/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.7/ref/settings/
"""

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
import sys
BASE_DIR = os.path.dirname(os.path.dirname(__file__))

site_packages = os.path.join(BASE_DIR, 'site-packages')
if not site_packages in sys.path:
    sys.path.insert(0, site_packages)

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.7/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'j))9$nc9!7i4zf-bqin3zi6w!ko-rlh6&+zel1&emu2!^mstt*'

# SECURITY WARNING: don't run with debug turned on in production!


ALLOWED_HOSTS = ['*']


# Application definition

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',

    'app',
)

MIDDLEWARE_CLASSES = (
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
)

ROOT_URLCONF = 'www.urls'

WSGI_APPLICATION = 'www.wsgi.application'


# Database
# https://docs.djangoproject.com/en/1.7/ref/settings/#databases

if 'APP_NAME' in os.environ:
    DEBUG = False
    import sae
    # sae.const:
    # ['ACCESS_KEY', 'APP_HASH', 'APP_NAME',
    #  'MYSQL_DB', 'MYSQL_HOST', 'MYSQL_HOST_S', 'MYSQL_PASS',
    #  'MYSQL_PORT', 'MYSQL_USER', 'SECRET_KEY', 'conf', 'os']
    DATABASES = {
        'default': {
            'ENGINE':   'django.db.backends.mysql',
            'NAME':     sae.const.MYSQL_DB,
            'USER':     sae.const.MYSQL_USER,
            'PASSWORD': sae.const.MYSQL_PASS,
            'HOST':     sae.const.MYSQL_HOST,
            'PORT':     sae.const.MYSQL_PORT,
        }
    }
else:
    import local_settings
    DEBUG = local_settings.DEBUG
    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.mysql',
            'NAME': local_settings.DATABASE_NAME,
            'HOST': local_settings.DATABASE_HOST,
            'PORT': local_settings.DATABASE_PORT,
            'USER': local_settings.DATABASE_USER,
            'PASSWORD': local_settings.DATABASE_PASSWORD,
        }
    }

TEMPLATE_DEBUG = DEBUG

# Internationalization
# https://docs.djangoproject.com/en/1.7/topics/i18n/

LANGUAGE_CODE = 'zh-cn'

LANGUAGES = (('en', u'English'), ('zh-cn',u'中文'))

TIME_ZONE = 'Asia/Shanghai'

USE_I18N = True

USE_L10N = True

USE_TZ = False


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.7/howto/static-files/

STATIC_URL = '/static/'

STATICFILES_DIRS = ('',
    os.path.join(os.path.dirname(__file__), 'static').replace('\\','/'),
)

TEMPLATE_DIRS = (
    os.path.join(os.path.dirname(__file__), 'templates').replace('\\','/'),
    'django.template.loaders.filesystem.Loader',
)

TEMPLATE_LOADERS = (
    'django.template.loaders.filesystem.Loader',
    'django.template.loaders.app_directories.Loader',
)
